<?php
require_once("Utils/Utils.php");
require_once("db/DAO/CartDAO.php");
require_once("controller/CartController.php");
require_once("filter/LoginFilter.php");

session_start();
$controller = new CartController();
$ref = Utils::requestPost('ref');

$filter = new LoginFilter();
$loggedUser = $filter->checkIfLogged();

	//user je logly, 
	$idA = Utils::requestPost('add');
	
	if(!is_null($idA)){
		$controller->saveToCart($loggedUser->getCartNumber(),$idA);
		echo "<br><span style='color:green;'>Polozka byla uspesne pridana do voziku</span><br>";
	}
		
	$controller->removalCheck($loggedUser->getCartNumber());	
		
	echo "Vitejte uzivateli c.".$loggedUser->getUserId()."<br><br>";
	echo "=Vas nakupni kosik=<br>";
	
	$obsah = $controller->loadAllItemsInCart($loggedUser->getCartNumber());
	
	if(!is_null($obsah)){
		$controller->renderCartItems($obsah);
	} else {
		echo "<br><b>Vas nakupni kosik je prazdny<b><br>";
	}
	
echo "<br><br><br>";

if(!is_null($ref)){
	echo "<a href='".$ref."'>zpet</a>";
} else {
	echo "<a href='index.php'>zpet</a>";
}

?>